﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Data;
using Touch2Like.DAL;
using Touch2Like.Model;
using Touch2Like.SharedLibrary;


namespace Touch2Like.Web
{
    public partial class Main : System.Web.UI.MasterPage
    {
        public string logcount = "102300";

        public string fancyWidth = "400px";
        public string FancyWidth
        {
            get { return fancyWidth; }
            set { fancyWidth = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            PH_NotUser.Visible = true;
            if (Session["Username"] != null)
            {
                //PH_User.Visible = true;
                //Username.Text = Session["Username"].ToString();
            }
            else if (Request.Cookies["CAMINTEL"] != null)
            {
                try
                {
                    UserInfo info = new UserInfo();
                    UserDAL User = new UserDAL();
                    info = User.GetUserByNameAndEmail(0, Request.Cookies["CAMINTEL"]["USERNAME"]);
                    if (info != null)
                    {
                        if (Utility.Encryption.Decrypt(Request.Cookies["CAMINTEL"]["PW"]) == Utility.Encryption.Decrypt(info.Password))
                        {
                            WebUtility.UserGUID = info.UserGuid;
                            WebUtility.Username = info.UserName;
                            //Username.Text = Session["Username"].ToString();
                        }
                    }
                    else
                    {
                        PH_NotUser.Visible = true;
                        //Username.Text = "Guest";
                        return;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                PH_NotUser.Visible = true;
                //Username.Text = "Guest";
                return;
            }

        }
        protected void lb_Signout_Click(object sender, EventArgs e)
        {
            if (Response.Cookies["CAMINTEL"] != null)
            {
                Response.Cookies["CAMINTEL"].Expires = DateTime.Now.AddDays(-1);
            }
            Session.Clear();
            
        }





        //    Tag tag = new Tag();
        //    logcount = (102300 + tag.GetLogCount()).ToString();

        //    Regex reg = new Regex("iPod|iPhone|Android|Opera Mini|BlackBerry|webOS|UCWEB|Blazer|PSP|IEMobile");
        //    if (reg.IsMatch(Request.UserAgent))
        //    {
        //        fancyWidth = "auto";
        //    }

        //    PH_User.Visible = false;
        //    PH_NotUser.Visible = false;

        //    //ShoppingCart cart = new ShoppingCart();

        //    if (WebUtility.UserGUID != null)
        //    {
        //        PH_User.Visible = true;

        //    //    DataTable dtCart = cart.GetNoPaid(WebUtility.UserGUID);
        //    //    lb_CartCount.Text = "(<span style='color:red;font-weight:bold;'>" + dtCart.Rows.Count.ToString() + "</span>)";
        //    }
        //    else
        //    {
        //        //if (WebUtility.TempUserID != 0)
        //        //{
        //        //    DataTable dtCart = cart.GetNoPaid(WebUtility.TempUserID);
        //        //    lb_CartCountNotUser.Text = "(<span style='color:red;font-weight:bold;'>" + dtCart.Rows.Count.ToString() + "</span>)";
        //        //}

        //        PH_NotUser.Visible = true;

        //        if (!string.IsNullOrEmpty(Request["next"]))
        //        {
        //            a_signup.HRef = "/Customer/signup.aspx?next=" + Server.UrlEncode(Server.UrlDecode(Request["next"]));
        //        }
        //    }
        //}

        private string _currentPage = "";
        public string CurrentPage
        {
            get { return _currentPage; }
            set { _currentPage = value; }
        }
    }
}